package com.ruoyi.loan.loan.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.LoanSignatureVo;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.loan.loan.domain.TbUser;
import com.ruoyi.loan.loan.mapper.TbUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.loan.loan.mapper.TbLoanSignatureMapper;
import com.ruoyi.loan.loan.domain.TbLoanSignature;
import com.ruoyi.loan.loan.service.ITbLoanSignatureService;

/**
 * 借款签章Service业务层处理
 * 
 * @author 杰少
 * @date 2023-01-14
 */
@Service
public class TbLoanSignatureServiceImpl implements ITbLoanSignatureService 
{
    @Autowired
    private TbLoanSignatureMapper tbLoanSignatureMapper;

    @Autowired
    private TbUserMapper tbUserMapper;

    /**
     * 查询借款签章
     * 
     * @param loanSignatureId 借款签章主键
     * @return 借款签章
     */
    @Override
    public TbLoanSignature selectTbLoanSignatureByLoanSignatureId(Long loanSignatureId)
    {
        return tbLoanSignatureMapper.selectTbLoanSignatureByLoanSignatureId(loanSignatureId);
    }

    /**
     * 查询借款签章列表
     * 
     * @param tbLoanSignature 借款签章
     * @return 借款签章
     */
    @Override
    public List<TbLoanSignature> selectTbLoanSignatureList(TbLoanSignature tbLoanSignature)
    {
        return tbLoanSignatureMapper.selectTbLoanSignatureList(tbLoanSignature);
    }

    /**
     * 新增借款签章
     * 
     * @param loanSignatureVo 借款签章
     * @return 结果
     */
    @Override
    public int insertTbLoanSignature(LoanSignatureVo loanSignatureVo)
    {
        TbUser tbUser = tbUserMapper.selectById(loanSignatureVo.getUserId());
        loanSignatureVo.setCreateBy(tbUser.getUserName());
        loanSignatureVo.setUpdateBy(tbUser.getUserName());
        loanSignatureVo.setCreateTime(null);
        loanSignatureVo.setUpdateTime(null);
        TbLoanSignature tbLoanSignature = new TbLoanSignature();
        BeanUtils.copyProperties(loanSignatureVo, tbLoanSignature);
        return tbLoanSignatureMapper.insertTbLoanSignature(tbLoanSignature);
    }

    /**
     * 修改借款签章
     * 
     * @param loanSignatureVo 借款签章
     * @return 结果
     */
    @Override
    public int updateTbLoanSignature(LoanSignatureVo loanSignatureVo)
    {
        TbUser tbUser = tbUserMapper.selectById(loanSignatureVo.getUserId());
        loanSignatureVo.setUpdateBy(tbUser.getUserName());
        loanSignatureVo.setUpdateTime(null);
        TbLoanSignature tbLoanSignature = new TbLoanSignature();
        BeanUtils.copyProperties(loanSignatureVo, tbLoanSignature);
        return tbLoanSignatureMapper.updateTbLoanSignature(tbLoanSignature);
    }

    /**
     * 批量删除借款签章
     * 
     * @param loanSignatureIds 需要删除的借款签章主键
     * @return 结果
     */
    @Override
    public int deleteTbLoanSignatureByLoanSignatureIds(Long[] loanSignatureIds)
    {
        return tbLoanSignatureMapper.deleteTbLoanSignatureByLoanSignatureIds(loanSignatureIds);
    }

    /**
     * 删除借款签章信息
     * 
     * @param loanSignatureId 借款签章主键
     * @return 结果
     */
    @Override
    public int deleteTbLoanSignatureByLoanSignatureId(Long loanSignatureId)
    {
        return tbLoanSignatureMapper.deleteTbLoanSignatureByLoanSignatureId(loanSignatureId);
    }
}
